package com.farsunset.cim.nio.mutual;

import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;

import com.kuaigou.cim.util.JSONHelper;

/**
 * 消息对象
 * 
 * @author @author 3979434@qq.com
 *
 */
public class Message implements Serializable {

	/**
	 * @author 3979434@qq.com 消息对象
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 消息id
	 */
	private String mid;

	/**
	 * 消息类型，用户自定义消息类别
	 */
	private String type;
	/**
	 * 消息标题
	 */
	private String title;
	/**
	 * 消息类容，于type 组合为任何类型消息，content 根据 format 可表示为 text,json ,xml数据格式
	 */
	private String content;

	/**
	 * 手机系统 1 android 2 ios
	 */
	private short channel;
	
	/**
	 * deviceToken  只有ios有deviceToken
	 */
	private String deviceToken;

	/**
	 * 消息发送者账号
	 */
	private String sender;
	/**
	 * 消息发送者接收者
	 */
	private String receiver;

	/**
	 * 校验码code
	 */
	private String verificationCode;

	/**
	 * 文件 url
	 */
	private String file;
	/**
	 * 文件类型
	 */
	private String fileType;

	/**
	 * content 内容格式
	 */
	private String format = "json";

	private String mapStr;

	public String getMapStr() {
		return mapStr;
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public void setMapStr(String mapStr) {
		this.mapStr = mapStr;
		try {
			if (mapStr != null && !"".equals(mapStr)) {
				data = (HashMap) JSONHelper.jsonToEntity(mapStr, HashMap.class);
			}

		} catch (IOException e) {
		}

	}

	/**
	 * 返回数据集合
	 */
	private HashMap<String, Object> data;

	/**
	 * 是否离线消息 true-是 false-不是
	 */
	private boolean isOffline = true;

	/**
	 * 离线消息保存时间 默认3天
	 */
	private long offlineTime = 3 * 24 * 60 * 60;

	/**
	 * 是否立即发送 true 立即发 false 不 （立即发送首先通过socket去发送
	 * 如果不在线则ios通过apns发送，android通过离线发送）
	 */
	private boolean isOffHand = false;

	private long timestamp;

	public Message() {
		data = new HashMap<String, Object>();
		timestamp = System.currentTimeMillis();
	}

	public boolean isOffHand() {
		return isOffHand;
	}

	public void setOffHand(boolean isOffHand) {
		this.isOffHand = isOffHand;
	}

	public short getChannel() {
		return channel;
	}

	public void setChannel(short channel) {
		this.channel = channel;
	}

	public boolean isOffline() {
		return isOffline;
	}

	public void setOffline(boolean isOffline) {
		this.isOffline = isOffline;
	}

	public long getOfflineTime() {
		return offlineTime;
	}

	public void setOfflineTime(long offlineTime) {
		this.offlineTime = offlineTime;
	}

	public HashMap<String, Object> getData() {
		return data;
	}

	public void setData(HashMap<String, Object> data) {
		this.data = data;
	}

	public Object get(String k) {
		return data.get(k);
	}

	public void put(String k, String v) {
		data.put(k, v);
	}

	public long getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(long timestamp) {
		this.timestamp = timestamp;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getSender() {
		return sender;
	}

	public void setSender(String sender) {
		this.sender = sender;
	}

	public String getReceiver() {
		return receiver;
	}

	public void setReceiver(String receiver) {
		this.receiver = receiver;
	}

	public String getFile() {
		return file;
	}

	public void setFile(String file) {
		this.file = file;
	}

	public String getFileType() {
		return fileType;
	}

	public void setFileType(String fileType) {
		this.fileType = fileType;
	}

	public String getFormat() {
		return format;
	}

	public void setFormat(String format) {
		this.format = format;
	}

	public String toString() {
		StringBuffer buffer = new StringBuffer();
		try {
			buffer.append(JSONHelper.objectToJson(this, Message.class));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return buffer.toString();
	}

	public String toXmlString() {
		return toString();
	}

	public String getMid() {
		return mid;
	}

	public void setMid(String mid) {
		this.mid = mid;
	}

	public String getVerificationCode() {
		return verificationCode;
	}

	public void setVerificationCode(String verificationCode) {
		this.verificationCode = verificationCode;
	}

	public String getDeviceToken() {
		return deviceToken;
	}

	public void setDeviceToken(String deviceToken) {
		this.deviceToken = deviceToken;
	}
}
